var express = require('express');
const axios = require('axios');

var router = express.Router();

router.get('/:id/detail', function (req, res, next) {
    // res.send("个人信息页面");
    res.render('app/addexam');
})

/**
 * @api {post} /addexam/upExam 发布评测
 * @apiName 发布评测
 * @apiGroup Exam
 *
 * @apiParam {String} pageNumber 第几页.
 *
 * @apiSuccess {String} firstname Firstname of the User.
 * @apiSuccess {String} lastname  Lastname of the User.
 */
router.post('/upExam', function (req, res, next) {
    let { postId, auditorStandard, digestionAvailability, nutritionData, userAvailability, userFeel, nutritionDegree, comment } = req.body
    var config = {
        method: 'post',
        baseURL: 'http://localhost:9022',
        url: '/tb-review/review',
        params: {
            auditorId: req.session.user.id,
            postId: postId,
            auditorStandard: auditorStandard,
            digestionAvailability: digestionAvailability,
            nutritionData: nutritionData,
            userAvailability: userAvailability,
            userFeel: userFeel,
            nutritionDegree: nutritionDegree,
            comment: comment
        },
        headers: {//指定响应头
            "Content-Type": "application/json;charset=utf-8",
            "Accept": "application/json"
        }
    }
    axios(config)
        .then(function (response) {
            // console.log(response);
            if (response.data.code == 'success') {
                console.log("发布成功")

                res.send({ err: 0, msg: "发布成功" })
                // res.redirect('app/index');
            } else {
                // console.log(response);
                res.send({ err: -1, msg: "发布失败" })
                console.log("发布失败")
            }
        })
        .catch(function (error) {
            // console.log(error);
            res.send({ err: -1, msg: "服务器错误" })
            console.log("服务器错误")
        });
})

module.exports = router;